﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
	public partial interface IService
{
[OperationContract]
string CardOpen_M_Add(CardOpen_M model ,int ACID);


[OperationContract]
string CardOpen_M_Update(CardOpen_M model ,int ACID);


[OperationContract]
string CardOpen_MBypid_Delete(string pid,int ACID);


[OperationContract]
CardOpen_M CardOpen_MBypid_Get(string pid,int ACID );


[OperationContract]
List<CardOpen_M> CardOpen_M_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加CardOpen_M表数据
/// <summary>
/// 添加CardOpen_M
/// </summary>
/// <param name="model">CardOpen_M实体</param>
/// <returns>空或错误</returns>
public string CardOpen_M_Add(CardOpen_M model,int ACID)
{
if(string.IsNullOrEmpty(model.pid))
{
return "『单据号』不能为空！";
}
if(model.WHer==null || model.WHer.Equals(Guid.Empty))
{
return "『数据维护操作人员』不能为空！";
}
if(model.iWHfinished==null )
{
return "『维护操作完成标志』不能为空！";
}
if(model.isfinish==null )
{
return "『付清标志』不能为空！";
}
if(model.ischeck==null )
{
return "『复核标志』不能为空！";
}
if(model.discount==null )
{
return "『折让金额』不能为空！";
}
if(model.balance==null )
{
return "『余额』不能为空！";
}
if(model.total==null )
{
return "『总金额』不能为空！";
}
if(model.ClientID==null || model.ClientID.Equals(Guid.Empty))
{
return "『客户ID』不能为空！";
}
if(model.opID==null || model.opID.Equals(Guid.Empty))
{
return "『开单员』不能为空！";
}
if(model.Pdate ==null )
{
return "『开单日期』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_M.Count(p=>p.pid==model.pid)>0)
{
return "主键已存在！";
}
ctx.CardOpen_M.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加CardOpen_M表数据事物用重构
/// <summary>
/// 添加CardOpen_M事物用重构
/// </summary>
/// <param name="model">CardOpen_M实体</param>
/// <returns>空或错误</returns>
private string CardOpen_M_Add(CardOpen_M model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(string.IsNullOrEmpty(model.pid))
{
return "『单据号』不能为空！";
}
if(model.WHer==null || model.WHer.Equals(Guid.Empty))
{
return "『数据维护操作人员』不能为空！";
}
if(model.iWHfinished==null )
{
return "『维护操作完成标志』不能为空！";
}
if(model.isfinish==null )
{
return "『付清标志』不能为空！";
}
if(model.ischeck==null )
{
return "『复核标志』不能为空！";
}
if(model.discount==null )
{
return "『折让金额』不能为空！";
}
if(model.balance==null )
{
return "『余额』不能为空！";
}
if(model.total==null )
{
return "『总金额』不能为空！";
}
if(model.ClientID==null || model.ClientID.Equals(Guid.Empty))
{
return "『客户ID』不能为空！";
}
if(model.opID==null || model.opID.Equals(Guid.Empty))
{
return "『开单员』不能为空！";
}
if(model.Pdate ==null )
{
return "『开单日期』不能为空！";
}
if(ctx.CardOpen_M.Count(p=>p.pid==model.pid)>0)
{
return "主键已存在！";
}
ctx.CardOpen_M.InsertOnSubmit(model);
return string.Empty;
}
#endregion



#region  修改CardOpen_M表数据
/// <summary>
/// 修改CardOpen_M
/// </summary>
/// <param name="model">CardOpen_M实体</param>
/// <returns>空或错误</returns>
public string CardOpen_M_Update(CardOpen_M model,int ACID)
{
if(string.IsNullOrEmpty(model.pid))
{
return "『单据号』不能为空！";
}
if(model.WHer==null || model.WHer.Equals(Guid.Empty))
{
return "『数据维护操作人员』不能为空！";
}
if(model.iWHfinished==null )
{
return "『维护操作完成标志』不能为空！";
}
if(model.isfinish==null )
{
return "『付清标志』不能为空！";
}
if(model.ischeck==null )
{
return "『复核标志』不能为空！";
}
if(model.discount==null )
{
return "『折让金额』不能为空！";
}
if(model.balance==null )
{
return "『余额』不能为空！";
}
if(model.total==null )
{
return "『总金额』不能为空！";
}
if(model.ClientID==null || model.ClientID.Equals(Guid.Empty))
{
return "『客户ID』不能为空！";
}
if(model.opID==null || model.opID.Equals(Guid.Empty))
{
return "『开单员』不能为空！";
}
if(model.Pdate ==null )
{
return "『开单日期』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_M.Count(p=>p.pid==model.pid)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
CardOpen_M CardOpen_Mmodel=ctx.CardOpen_M.Single(p => p.pid==model.pid);
if(!string.IsNullOrEmpty(model.pid))
{
CardOpen_Mmodel.pid=model.pid;
}
if(model.Pdate!=null )
{
CardOpen_Mmodel.Pdate=model.Pdate;
}
if(model.opID!=null || model.opID.Equals(Guid.Empty))
{
CardOpen_Mmodel.opID=model.opID;
}
if(!string.IsNullOrEmpty(model.WarehouseID))
{
CardOpen_Mmodel.WarehouseID=model.WarehouseID;
}
if(!string.IsNullOrEmpty(model.orderid))
{
CardOpen_Mmodel.orderid=model.orderid;
}
if(model.ClientID!=null || model.ClientID.Equals(Guid.Empty))
{
CardOpen_Mmodel.ClientID=model.ClientID;
}
if(!string.IsNullOrEmpty(model.linkman))
{
CardOpen_Mmodel.linkman=model.linkman;
}
if(!string.IsNullOrEmpty(model.tel))
{
CardOpen_Mmodel.tel=model.tel;
}
if(model.total!=null )
{
CardOpen_Mmodel.total=model.total;
}
if(model.balance!=null )
{
CardOpen_Mmodel.balance=model.balance;
}
if(model.discount!=null )
{
CardOpen_Mmodel.discount=model.discount;
}
if(model.JSempid!=null || model.JSempid.Equals(Guid.Empty))
{
CardOpen_Mmodel.JSempid=model.JSempid;
}
if(model.ischeck!=null )
{
CardOpen_Mmodel.ischeck=model.ischeck;
}
if(model.Checkempid!=null || model.Checkempid.Equals(Guid.Empty))
{
CardOpen_Mmodel.Checkempid=model.Checkempid;
}
if(model.isfinish!=null )
{
CardOpen_Mmodel.isfinish=model.isfinish;
}
if(!string.IsNullOrEmpty(model.Remarks))
{
CardOpen_Mmodel.Remarks=model.Remarks;
}
if(model.iWHfinished!=null )
{
CardOpen_Mmodel.iWHfinished=model.iWHfinished;
}
if(model.WHer!=null || model.WHer.Equals(Guid.Empty))
{
CardOpen_Mmodel.WHer=model.WHer;
}
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion



#region  删除CardOpen_M表Bypid数据
/// <summary>
/// 删除CardOpen_MBypid
/// </summary>
/// <param name="pid">单据号</param>
/// <returns>空或错误</returns>
public string CardOpen_MBypid_Delete(string pid,int ACID)
{
if(string.IsNullOrEmpty(pid))
{
return "『单据号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_M.Count(p=>p.pid==pid)!=1)
{
return null;
}
CardOpen_M model=ctx.CardOpen_M.Single(p => p.pid== pid);
ctx.CardOpen_M.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除CardOpen_M表Bypid数据[事物用重构]
/// <summary>
/// 删除CardOpen_MBypid[事物用重构]
/// </summary>
/// <param name="pid">单据号</param>
/// <returns>空或错误</returns>
private string CardOpen_MBypid_Delete(string pid,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(string.IsNullOrEmpty(pid))
{
return "『单据号』不能为空！";
}
if(ctx.CardOpen_M.Count(p=>p.pid==pid)!=1)
{
return null;
}
CardOpen_M model=ctx.CardOpen_M.Single(p => p.pid== pid);
ctx.CardOpen_M.DeleteOnSubmit(model);
return string.Empty;
}
#endregion



#region  获取CardOpen_M表Bypid数据
/// <summary>
/// 获取CardOpen_MBypid
/// </summary>
/// <param name="pid">单据号</param>
/// <returns>当前表</returns>
public CardOpen_M CardOpen_MBypid_Get(string pid,int ACID)
{
if(string.IsNullOrEmpty(pid))
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.CardOpen_M.Count(p=>p.pid==pid)!=1)
{
return null;
}
return ctx.CardOpen_M.SingleOrDefault(p=>p.pid==pid);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion



#region  获取CardOpen_M表数据
/// <summary>
/// 获取CardOpen_M
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_M></returns>
public List<CardOpen_M> CardOpen_M_Get(Expression<Func<CardOpen_M, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_M.ToList();
}
 else 
{
return ctx.CardOpen_M.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_M.Where(predicate).ToList();
}
 else 
{
return ctx.CardOpen_M.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  获取CardOpen_M表数据
/// <summary>
/// 获取CardOpen_M
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_M></returns>
public List<CardOpen_M> CardOpen_M_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return CardOpen_M_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion


#region  获取CardOpen_M表数据计数
/// <summary>
/// 获取CardOpen_M表数据计数
/// </summary>
/// <returns>List<CardOpen_M></returns>
public int CardOpen_M_GetCount(Expression<Func<CardOpen_M, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.CardOpen_M.Count();

}
 else
{
return ctx.CardOpen_M.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion




#region  获取CardOpen_M分页表数据
/// <summary>
/// 获取CardOpen_M分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<CardOpen_M></returns>
public List<CardOpen_M> CardOpen_M_Getpage(int pageIndex, int pageSize,Expression<Func<CardOpen_M, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_M.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.CardOpen_M.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.CardOpen_M.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.CardOpen_M.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  批量修改CardOpen_M表数据
/// <summary>
/// 批量修改CardOpen_M
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_M, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<CardOpen_M,CardOpen_M>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int CardOpen_M_batchUpdate(Expression<Func<CardOpen_M, bool>> predicate,Expression<Func<CardOpen_M, CardOpen_M>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.CardOpen_M.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量修改CardOpen_M表数据事物用重构
/// <summary>
/// 批量修改CardOpen_M事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_M, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<CardOpen_M,CardOpen_M>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int CardOpen_M_batchUpdate(Expression<Func<CardOpen_M, bool>> predicate,Expression<Func<CardOpen_M, CardOpen_M>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.CardOpen_M.Update(predicate, updater);
return ok;
}
#endregion


#region  批量删除CardOpen_M表数据
/// <summary>
/// 批量删除CardOpen_M
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_M, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int CardOpen_M_batchDel(Expression<Func<CardOpen_M, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.CardOpen_M.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量删除CardOpen_M表数据事物用重构
/// <summary>
/// 批量删除CardOpen_M事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<CardOpen_M, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int CardOpen_M_batchDel(Expression<Func<CardOpen_M, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.CardOpen_M.Delete(predicate);
return ok;
}
#endregion


}
}

